using System;
using System.Web;
using CSI.Directory.Core.Model;

namespace C3.Directory.Services
{
    public interface ISessionService
    {
        User GetUser();
        void Clear();
        void UpdateUser(User user);
        User CurrentUser { get; set; }
    }

    public class SessionService : ISessionService
    {
        private const string UserKey = "User";
        public User GetUser()
        {

            return HttpContext.Current.Session[UserKey] as User;

        }
        public void Clear()
        {
            HttpContext.Current.Session.Clear();
        }
        
        public void UpdateUser(User user)
        {
            HttpContext.Current.User = user;
            HttpContext.Current.Session[UserKey] = user;
        }

        public User CurrentUser
        {
            get { return HttpContext.Current.Session[UserKey] as User; }
            set
            {
                HttpContext.Current.User = value;
                HttpContext.Current.Session[UserKey] = value;
            }
        }
    }
}